package club.emergency.wechat.aliyun_sms.consumer.controller;

import club.emergency.wechat.aliyun_sms.consumer.service.SendMessageConsumer;
import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.utils.JsonConvert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.aliyun_sms.consumer.controller
 * Date: 2018/11/13
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Api
@RestController
@RequestMapping("/sms")
public class SendMessageController {

    private SendMessageConsumer sendMessageConsumer;

    public SendMessageController(SendMessageConsumer sendMessageConsumer) {
        this.sendMessageConsumer = sendMessageConsumer;
    }

    @PostMapping("/send-sms")
    @ApiOperation("根据用户输入的手机号发送短信接口")
    @ApiImplicitParam(name = "phoneNumber", value = "手机号", required = true, dataType = "string", paramType = "query")
    public ResponseEntity sendSms(String phoneNumber) {
        return new JsonConvert<ResponseEntity>().jsonDecode(sendMessageConsumer.sendVerificationSms(phoneNumber), ResponseEntity.class);
    }

    @PostMapping("/confirm-verification")
    @ApiOperation("验证用户输入的手机号和验证码是否对应")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phoneNumber", value = "手机号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "confirmCode", value = "验证码", required = true, dataType = "string", paramType = "query")
    })
    public ResponseEntity confirmVerification(String phoneNumber, String confirmCode) {
        return new JsonConvert<ResponseEntity>().jsonDecode(sendMessageConsumer.confirmVerification(phoneNumber, confirmCode), ResponseEntity.class);
    }
}
